package com.corpdata.app.project.controller;

import java.security.MessageDigest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.corpdata.app.customer.service.CustomerStaffService;
import com.corpdata.app.customer.service.CustomerTeamService;
import com.corpdata.app.project.entity.ProjectDoor;
import com.corpdata.app.project.service.ProjectDoorService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.common.utils.HttpUtils;
import com.corpdata.core.base.BaseController;
import com.corpdata.system.log.WebLog;

/**
 * 分店门禁
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-07-16 11:00:04
 */
 
@Controller
@RequestMapping("app/projectDoor")
public class ProjectDoorController extends BaseController{
	@Autowired
	private CustomerStaffService customerStaffService;
	@Autowired
	private CustomerTeamService customerTeamService;
	@Autowired
	private ProjectDoorService projectDoorService;
	
	//首页页面
	@GetMapping("/index")
	public String index(){
		return "app/project/door/door_index";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	public Result save(ProjectDoor record){
		return projectDoorService.save(record);
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	public Result update(ProjectDoor record){
		return projectDoorService.update(record);
	}
		
	//开门记录页面
	@GetMapping("/inOutList/{projectId}")
	public String inOutList(ModelMap map,@PathVariable("projectId") String projectId){
	    return "app/project/door/door_inout_list";
	}
	
	//门禁管理页面
	@GetMapping("/doorManage/{projectId}")
	public String doorManage(ModelMap map,@PathVariable("projectId") String projectId){
	    return "app/project/door/door_manage";
	}
	
	//新增页面门禁权限
	@GetMapping("/toAdd/{projectId}")
	public String add(ModelMap map,@PathVariable("projectId") String projectId){
		map.put("teams", customerTeamService.selectByPid(projectId));
		return "app/project/door/door_manage_add";
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id,ModelMap map){
		map.put("record", projectDoorService.findById(id));
		return "app/project/door/door_manage_edit";
	}
	
	@RequestMapping("/details/{id}")
	public String details(ModelMap map,@PathVariable("id") String id){
		map.put("record", projectDoorService.findById(id));
		return "app/project/door/door_manage_details";
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		return projectDoorService.findByPage(dgRequest);
	}
	
	@ResponseBody
	@RequestMapping("/selectAll/{pid}")
	public List<ProjectDoor> getSelectJsonData(@PathVariable("pid") String pid){
		return projectDoorService.selectAllByCombox(pid);
	}
	
	@ResponseBody
	@RequestMapping("/getQrcode")
	public String getqrcode(String personCode){
		String result = projectDoorService.getQrcode(personCode, "2018-08-06 16:00:00", "2018-08-06 19:00:00", "9:00", "10:00", "123", "456");
		return result;
	}
	
}
